package JZOffer;

import java.util.ArrayDeque;
import java.util.Deque;

// 用两个栈实现队列
public class JzOffer09 {
    static class CQueue {
        private Deque<Integer> stack1;
        private Deque<Integer> stack2;

        public CQueue() {
            stack1 = new ArrayDeque<>();
            stack2 = new ArrayDeque<>();
        }

        public void appendTail(int value) {
            stack2.push(value);
        }

        public int deleteHead() {
            if (stack1.isEmpty()) {
                while (!stack2.isEmpty()) {
                    stack1.push(stack2.pop());
                }
            }
            if (stack1.isEmpty()) {
                return -1;
            } else {
                return stack1.pop();
            }
        }
    }
}
